/*
 *  Copyright (C) 2010 Glauco
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.balisunrise.swing.transaction;

import org.balisunrise.common.Bindable;
import org.balisunrise.common.BindingGroup;
import org.balisunrise.common.EntityFieldType;
import org.balisunrise.common.abstracts.AbstractEmbeddedFieldLayout;

/**
 * Esta interface representa um campo de um entidade, porém este campo não é uma
 * coluna da tabela da entidade, e sim uma outra entidade com seus próprios
 * campos.<br>
 * Objetos dessa interface contém os LayoutableFields da classe que o campo
 * representa, portanto esses objetos são um LayoutableField e um FieldsGroup.
 * Esse objeto não possui um FieldLayout próprio, e sim um conjunto de
 * FieldLayout dos LayoutableField que ele possui.
 * 
 * @author glauco
 */
public class EmbeddedPanelField extends AbstractEmbeddedFieldLayout
        implements org.balisunrise.common.EmbeddedPanelField{


    public void bindComponent(BindingGroup bindingGroup,
            Object source, String property) {

        String thisProperty = property + "." + fieldName;

        for (org.balisunrise.common.FieldLayout fl : layouts) {
            if(fl instanceof Bindable){
                Bindable b = (Bindable) fl;
                b.bindComponent(bindingGroup, source, thisProperty);
            }
        }
    }

    public void clearComponentsValues() {
        for (org.balisunrise.common.FieldLayout fl : layouts) {
            fl.clearComponentsValues();
        }
    }

    public EntityFieldType getEntityFieldType() {
        return EntityFieldType.EMBEDDED_PANEL_FIELD;
    }
}
